package com.neuedu.hcp.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.hcp.entity.Distribute;
import com.neuedu.hcp.entity.RecoveryPlan;
import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.service.IDistributeService;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 * http://127.0.0.1:8081/distribute/planList
 */
@RestController
@RequestMapping("/distribute")
public class DistributeController {
    @Resource
    IDistributeService distributeService;

    /**
     * 分页展示数据
     * @param currentPage
     * @param size
     * @param distribute
     * @return
     */
    @GetMapping("/planList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             Distribute distribute){
        return distributeService.getPlanListByPage(currentPage,size,distribute);
    }

    /**
     * 添加数据
     * @param distribute
     * @return
     */
    @GetMapping("/insert")
    public RespBean insert(Distribute distribute){
        if(distributeService.insert(distribute)<=0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }

    /**
     * 修改数据
     * @param distribute
     * @return
     */
    @PostMapping("/update")
    public RespBean update(@RequestBody Distribute distribute){
        if(distributeService.updateById(distribute)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除数据
     * @param patientId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer patientId){
        if(distributeService.removeById(patientId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
